import axios from "axios";
import{ ElMessage } from "element-plus";

const service = axios.create({
  baseURL: process.env.VUE_APP_BASE_API,
  timeout: 10000,
  withCredentials: true
})

service.interceptors.request.use(
    config => {
      return config
    },
    error => {
      return Promise.reject(error)
    }
)
service.interceptors.response.use(
    response => {
      const res = response.data
      return res
    },
    error => {
      console.log(error);
      ElMessage({
        message: error.message,
        type: 'error',
        duration: 2000
      })
      return Promise.reject(error.message)
    }
)

export default service
